//
//  TabBarView.swift
//  loveHHEveryDay
//
//  Created by yw on 2025/4/2.
//

import SwiftUI

struct TabBarView: View {
    @State var currentIndex:Int = 0
    var body: some View {
        TabView(selection: $currentIndex) {
            HomeView()
                .tabItem {
//                    Image(systemName: "1.circle")
                    Image(currentIndex == 0 ? "tab_home_sel":"tab_home_nor")
                    Text("首页")
                }.tag(0)
            MomentView()
                .tabItem {
                    Image(currentIndex == 1 ? "tab_moment_sel":"tab_moment_nor")
                    Text("时刻")
                }.tag(1)
            ProfileView()
                .tabItem {
                    Image(currentIndex == 2 ? "tab_profile_sel":"tab_profile_nor")
                    Text("我的")
                }.tag(2)
            
        }.accentColor(.colorTextMain)
//            .tint(.colorTextMain)
            .onChange(of: currentIndex) { newValue in
                let generator = UIImpactFeedbackGenerator(style: .light)
                generator.prepare()
                generator.impactOccurred()
            }
            .onAppear {
                let tabbarAppearance = UITabBarAppearance()
                //                   tabbarAppearance.configureWithOpaqueBackground()
                //                   tabbarAppearance.backgroundColor = .white
                tabbarAppearance.shadowImage = UIImage()
                tabbarAppearance.shadowColor = .clear
                tabbarAppearance.backgroundColor = .white
                UITabBar.appearance().standardAppearance = tabbarAppearance
                // 设置导航栏颜色
                let navibarAppearance = UINavigationBarAppearance()
                navibarAppearance.shadowImage = UIImage()
                navibarAppearance.shadowColor = UIColor.clear
                navibarAppearance.backgroundColor = .white
                navibarAppearance.titleTextAttributes = [.foregroundColor:UIColor(named: "color_text_main") ?? .black]
                navibarAppearance.largeTitleTextAttributes = [.foregroundColor:UIColor(named: "color_text_main") ?? .black]
                UINavigationBar.appearance().standardAppearance = navibarAppearance
                //                UINavigationBar.appearance().backIndicatorImage = UIImage(systemName: "arrow.backward.square.fill")
                //                UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(systemName: "arrow.backward.square.fill")
            }
    }
}


